import 'package:json_annotation/json_annotation.dart';

/// socket 消息里面的message Type
enum HBRtmMessageDetailType {
  /// 这个type 的整体值设置在41以下，不能超过41
  text(1, '文本消息'),
  gift(2, '礼物消息'),
  safeMsg(10085, '进入房间安全提醒'),
  msgEndtype(10086, '自定义消息结束');

  final int value;
  final String name;

  const HBRtmMessageDetailType(this.value, this.name);

  // 值到枚举的映射表
  static final Map<int, HBRtmMessageDetailType> _byValue = {
    for (final e in HBRtmMessageDetailType.values) e.value: e,
  };

  // 通过整数值获取枚举
  static HBRtmMessageDetailType? fromValue(int value) => _byValue[value];
}

// 自定义 JsonConverter
class HBRtmMessageDetailTypeConverter
    extends JsonConverter<HBRtmMessageDetailType?, int?> {
  const HBRtmMessageDetailTypeConverter();

  @override
  HBRtmMessageDetailType? fromJson(int? json) {
    if (json == null) {
      return null;
    }
    return HBRtmMessageDetailType.fromValue(json);
  }

  @override
  int? toJson(HBRtmMessageDetailType? object) {
    return object?.value;
  }
}
